package com.hmall.search.web;

import com.hmall.common.PageBean;
import com.hmall.feign.client.ItemClient;
import com.hmall.item.pojo.Item;
import com.hmall.search.constants.ItemConstants;
import com.hmall.search.dto.SearchDto;
import com.hmall.search.service.SearchService;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

import java.io.IOException;
import java.util.List;
import java.util.Stack;

@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    private SearchService sService;

    @GetMapping("suggestion")
    public String suggestion(@RequestBody String key) {
        return "suggestion";
    }

    @GetMapping("filterlist")
    public PageBean<Item> pageQuery(Integer page, Integer size,String sortBy,String category,String brand) {
        PageBean<Item> pageBean = sService.pageQuery(page, size, sortBy, category, brand);
        return pageBean;

    }

    @Autowired
    public RestHighLevelClient client;
    @Autowired
    ItemClient itemClient;

    @PostMapping("additem")
    public int additem(@RequestBody List<Item> itemlist) throws IOException {


       return 0;
    }
    @Autowired
    SearchService searchService;
    @PostMapping("list")
    public PageBean<Item> search(@RequestBody SearchDto dto) {

        PageBean<Item> pageBean = searchService.search(dto);
        return pageBean;
    }
    @GetMapping("mysql2ES")
    public void mysql2ES() throws IOException {
        searchService.mysql2ES();
    }
}
